<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of customer_model
 *
 * @author Hadi
 */
class polist_model extends Default_My_Model {
    //put your code here
    function __construct() {
        parent::__construct();
    }

    public function getPOlist($whr) {
        $QUERY = "SELECT id_po, nomor_po, diskon FROM data_po_to_supplier ".($whr ? " WHERE $whr " : "")." order by id_po desc";
        return $this->db->query($QUERY);
    }

    public function getDetailPOlist($kode) {
        $QUERY = "SELECT q.id_po as list_po_id, q.nomor_po, c.* FROM data_po_to_supplier q LEFT JOIN master_supplier c
                ON q.id_supplier = c.id_supplier
            WHERE q.id_po = '$kode' order by q.id_po desc";
        return $this->get_object($QUERY);
    }

    public function getItem($id_po) {
        return $this->db->query("SELECT i.id_item, i.nama_item, i.satuan_beli, i.quantity,
                                 CASE 
                                    WHEN q.using_ppn = 0 THEN i.harga_jual
                                    ELSE i.harga_jual + i.harga_jual * 0.1
                                 END as harga_jual,
                                 CASE
                                    WHEN q.using_ppn = 0 THEN i.harga_jual_dollar
                                    ELSE i.harga_jual_dollar + i.harga_jual_dollar * 0.1 
                                 END as harga_jual_dollar
                                 FROM data_po_to_supplier_item i LEFT JOIN data_po_to_supplier q ON i.id_po = q.id_po
                                 WHERE q.id_po = ?", array($id_po));
    }

}

?>
